<?php

namespace app\admin\controller;
use think\Config;
use think\Loader;
use think\Db;

class Index extends Base
{
    public function index()
    {
        return $this->fetch('/index');
    }


    /**
     * [indexPage 后台首页]
     * @return [type] [description]
     * @author 【朱沪宁】
     */
    public function indexPage()
    {
         //今日新增会员
        $today = strtotime(date('Y-m-d 00:00:00'));//今天开始日期     
        $map['create_time'] = array('egt', $today);
        $member = Db::name('member')->where($map)->count();
        $this->assign('member', $member);

        $info = array(
            'web_server' => $_SERVER['SERVER_SOFTWARE'],
            'onload'     => ini_get('upload_max_filesize'),
            'think_v'    => THINK_VERSION,
            'phpversion' => phpversion(),
        );
        $this->assign('info',$info);
        
        $map = []; 
        $rolename = session('rolename');
        $orgid = session('orgid');
        if($rolename=='施工项目部'||$rolename=='施工单位'){
            $map["think_project.organization_id"] = ['eq',"" . $orgid . ""]; 
        } 
        //巡检人员
        if($rolename=='巡检人员') {  
          //  $temp12=$project->getOneprojectByxunjianId(session('uid'));
            if($temp12!=null)
            {
                $map['think_project.id']=$temp12['id'];
            } 
            //表示不是总公司级别的,需要加这个筛选条件,表示项目所属公司
           if($orgid!=1&&$orgid!=2)
           $map['think_project.organization_id'] = ['eq',"" . $orgid . ""];    
        }        
        
       // $zgbc=$project->getCountProjectWhere($map);
        //$this->assign('zgbc',$zgbc);
        $map=[];
        $shmap=[];
        
        $map["think_equipment.isdelete"] = ['eq','0'];

        if($rolename=='施工项目部'){
           // $proj = $project->getOneprojectByuid(session('uid'));
            $map['think_equipment.project_id']=$proj['id'];
        }

        if($orgid!=1&&$orgid!=2){
            $map['think_equipment.organization_id']=$orgid;
        }

        //巡检人员
        if($rolename=='巡检人员') {  
          //  $temp12=$project->getOneprojectByxunjianId(session('uid'));
            if($temp12!=null)
            {
                $map['think_equipment.project_id']=$temp12['id'];
               
            } 
        }      


        $map = [];
        $map["think_equipment_test.status"] = ['eq','0']; 
        if($rolename=='施工项目部'||$rolename=='施工单位'){
            $map["think_equipment_test.organization_id"] = ['eq',"" . $orgid . ""]; 
        }
        $Nowpage = 1;
        $limits = 5;
        
        $map = [];
        $map["think_zlqy.status"] = ['eq','0']; 
        if($rolename=='施工项目部'||$rolename=='施工单位'){
            $map["think_zlqy.organization_id"] = ['eq',"" . $orgid . ""]; 
        }
        $Nowpage = 1;
        $limits = 5;

        return $this->fetch('index');
    }



    /**
     * [userEdit 修改密码]
     * @return [type] [description]
     * @author 【朱沪宁】
     */
    public function editpwd(){

        if(request()->isAjax()){
            $param = input('post.');
            $user=Db::name('admin')->where('id='.session('uid'))->find();
            if(md5(md5($param['old_password']) . config('auth_key'))!=$user['password']){
               return json(['code' => -1, 'url' => '', 'msg' => '旧密码错误']);
            }else{
                $pwd['password']=md5(md5($param['password']) . config('auth_key'));
                Db::name('admin')->where('id='.$user['id'])->update($pwd);
                session(null);
                cache('db_config_data',null);//清除缓存中网站配置信息
                return json(['code' => 1, 'url' => 'index/index', 'msg' => '密码修改成功']);
            }
        }
        return $this->fetch();
    }


    /**
     * 清除缓存
     */
    public function clear() {
        if (delete_dir_file(CACHE_PATH) && delete_dir_file(TEMP_PATH)) {
            return json(['code' => 1, 'msg' => '清除缓存成功']);
        } else {
            return json(['code' => 0, 'msg' => '清除缓存失败']);
        }
    }

}
